package cn.wolfcode.luowowo.web.controller;

import cn.wolfcode.luowowo.SmsFeignApi;
import cn.wolfcode.luowowo.common.Result;
import cn.wolfcode.luowowo.feign.UserInfoFeignApi;
import cn.wolfcode.luowowo.msg.WebSiteCodeMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wolfcode-lanxw
 */
@RestController
@RequestMapping("/regist")
public class RegisterController {
    @Autowired
    private SmsFeignApi smsFeignApi;
    @Autowired
    private UserInfoFeignApi userInfoFeignApi;
    //检查用户手机是否存在
    @GetMapping("/checkPhone")
    public Result checkPhone(String phone){
        Result result = userInfoFeignApi.checkPhone(phone);
        if(result==null){
            return Result.error(WebSiteCodeMsg.MEMBER_SERVER_ERROR);
        }
        System.out.println(result);
        return result;
    }
    @PostMapping("/userRegist")
    public Result userRegist(String phone, String nickname, String password, String rpassword, String verifyCode){
        Result result = smsFeignApi.checkVerifyCode(phone, verifyCode);
        if(result==null){
            return Result.error(WebSiteCodeMsg.MSG_SERVER_ERROR);
        }
        if(result.hasError()){
            return result;
        }
        Result result2 = userInfoFeignApi.userRegist(phone, nickname, password, rpassword);
        if(result2==null){
            return Result.error(WebSiteCodeMsg.MEMBER_SERVER_ERROR);
        }
        return result2;
    }
}
